package com.lantosec.hmrp.core.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableSwaggerBootstrapUi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Api配置和启动类
 *
 * @author 杨成宇
 * @version 1.0
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUi
public class Swagger2Config {
    /**
     * 创建一个Docket对象
     * 调用select()方法，
     * 生成ApiSelectorBuilder对象实例，该对象负责定义外漏的API入口
     * 通过使用RequestHandlerSelectors和PathSelectors来提供Predicate，在此我们使用any()方法，将所有API都通过Swagger进行文档管理
     *
     * @return
     */
    @Bean
    public Docket createRestApi_System() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/system/**"))
                .build()
                .groupName("系统管理")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_supplier() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/supplier/**"))
                .build()
                .groupName("供应商管理")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_eval() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/eval/**"))
                .build()
                .groupName("综合考评")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_internal() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/internal/**"))
                .build()
                .groupName("内部满意度")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_morality() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/morality/**"))
                .build()
                .groupName("医德医风")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_revisit() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/revisit/**"))
                .build()
                .groupName("患者回访")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_external() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/external/**"))
                .build()
                .groupName("患者评价")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_notify() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/notify/**"))
                .build()
                .groupName("通知")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_Workflow() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/workflow/**"))
                .build()
                .groupName("流程管理")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_Form() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/form/**"))
                .build()
                .groupName("表单管理")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_warning() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/warning/**"))
                .build()
                .groupName("预警管理")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_monitor() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/monitor/**"))
                .build()
                .groupName("大屏")
                .pathMapping("/");
    }


    @Bean
    public Docket createRestApi_assets() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/category/**"))
                .build()
                .groupName("固定资产管理")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_archives() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/archives/**"))
                .build()
                .groupName("档案管理")
                .pathMapping("/");
    }

    @Bean
    public Docket createRestApi_report() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/report/**"))
                .build()
                .groupName("报表")
                .pathMapping("/");
    }


    //@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.basePackage("tech.wuzi.ecm.test")) //扫描的是自己写Controller的包名
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("HMRP API") //标题
                .description("现代化管理与风险防控智慧云平台") //简介
                .termsOfServiceUrl("") //服务条款
                .contact(new Contact("蓝途方鼎", "com.lantosec.hmrp", "ycy198168@163.comp")) //作者个人信息
                .version("1.0")//版本
                .build();
    }
}
